package com.ct.gd.passport.common.webservice;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

public class WebServiceUtil {

	public static final Object callWebService(String nameSpace, String wsdl, String methodName) {
		return callWebService(nameSpace, wsdl, methodName, null);
	}

	public static final Object callWebService(String nameSpace, String wsdl, String methodName, Map params) {
		try {
			SoapObject soapObject = new SoapObject(nameSpace, methodName);
			if (params != null && !params.isEmpty()) {
				for (@SuppressWarnings("rawtypes")
				Iterator it = params.entrySet().iterator(); it.hasNext();) {
					@SuppressWarnings("unchecked")
					Map.Entry<String, Object> e = (Map.Entry<String, Object>) it.next();
					soapObject.addProperty(e.getKey().toString(), e.getValue());
				}
			}
			SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			envelope.dotNet = true;
			envelope.setOutputSoapObject(soapObject);//envelope.bodyOut=request;         
			HttpTransportSE httpTranstation = new HttpTransportSE(wsdl);
			httpTranstation.call(nameSpace + methodName, envelope);
			return envelope.getResponse();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException ee) {
			ee.printStackTrace();
		}
		return null;
	}

}
